home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / pack / crunchmania / lzdecrunch_mc68000.asm < prev    next >
Assembly Source File  |  1980-01-03  |  4KB  |  198 lines

  1. *******************************************************************************
  2. * CrunchMania LZ-Huffman "TURBO" DATA-DECRUNCH! (Standard MC68000 Version)
  3. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  4. *    Allows decrunching of CrunchMania LZ-Huffman Datafiles! This source is
  5. * NOT from any official 'release' archive. Its an optimised resourced version
  6. * which contains no nasty slow 'mulu's & has been speeded up in several ways.
  7. * Resourced, optimised & address error fixed by LSD! CALL OUR BOARDS!
  8. *
  9. * INPUTS:    a0=source (packed data)
  10. *        a1=destination (depack destination)
  11. *
  12. * OUTPUTS:    a1=destination (start of decrunched data)
  13. *******************************************************************************
  14.  
  15. ;-------------- LZData Decrunch
  16.  
  17. Example:    lea    source(pc),a0    ;a0=source    
  18.         lea    16(a0),a1    ;a1=dest
  19.         bsr.b    UnpackLZ    ;call the decruncher
  20.         rts
  21.  
  22. ;-------------- Actual Decruncher
  23.                     
  24. UnpackLZ:    move.l    a0,a2        ;make copy of source address
  25. ;        cmp.l    #"CrM2",(a2)+    ;Check for "CrM2" LZ-Huffman Header
  26. ;        beq.s    LZDecrunch    ;yes it is packed, lets depack it!
  27. ;not_crm:    rts
  28.         
  29. LZDecrunch:    ;tst.w    (a2)+        ;skip minimum 2nd distance
  30.         move.l    (a2)+,d1    ;original size
  31.         move.l    (a2)+,d2    ;packed length
  32.         move.l    a1,a5        ;Decrunched Anfang (hier Ende des Decrunchens)
  33.         add.l    d1,a1
  34.         add.l    d2,a2
  35.         lea    128(a1),a6    ;128 bytes (of minimum safe distance!)
  36.         move.l    a6,d7
  37.         andi.b    #%11111110,d7    ;mask out odd address errors on mc68k!
  38.         move.l    d7,a6
  39.         move.w    -(a2),d0    ;Anz Bits in letztem Wort
  40.         move.l    -(a2),d6    ;1.LW
  41.         moveq    #16,d7        ;Anz Bits
  42.         sub.w    d0,d7        ;Anz Bits, die rotiert werden müssen
  43.         lsr.l    d7,d6        ;1.Bits an Anfang bringen
  44.         move.w    d0,d7        ;Anz Bits, die noch im Wort sind
  45.  
  46.         moveq    #16,d3
  47. LZ20A:        lea    $49E(a6),a0
  48.         moveq    #4-1,d2
  49.         moveq    #0,d4
  50. LZ210:        move.l    d4,(a0)+
  51.         move.l    d4,(a0)+
  52.         move.l    d4,(a0)+
  53.         move.l    d4,(a0)+
  54.         dbra    d2,LZ210
  55.  
  56.         lea    $4BE(a6),a0
  57.         lea    $9E(a6),a4
  58.         moveq    #9,d2
  59.         bsr.w    LZ300
  60.         lea    $49E(a6),a0
  61.         lea    $80(a6),a4
  62.         moveq    #4,d2
  63.         bsr.w    LZ300
  64.  
  65.         lea    $4BE(a6),a3
  66.         lea    -2(a6),a4
  67.         bsr.w    lzfast
  68.  
  69.         lea    $49E(a6),a3
  70.         lea    $1E(a6),a4
  71.         bsr.w    lzfast
  72.  
  73.         moveq    #$10,d1
  74.         bsr.w    LZ2C8
  75.         move.w    d0,d5
  76.         lea    $9E(a6),a0
  77.         lea    -$1E(a0),a5
  78.  
  79. LZ258:        move.l    a6,a4
  80.         bsr.s    LZ29C
  81.         btst    #8,d0
  82.         bne.s    LZ28A
  83.         move.w    d0,d4
  84.         lea    $20(a6),a4
  85.         exg    a0,a5
  86.         bsr.s    LZ29C
  87.         exg    a0,a5
  88.         move.w    d0,d1
  89.         move.w    d0,d2
  90.         bne.s    LZ278
  91.         moveq    #1,d1
  92.         moveq    #$10,d2
  93. LZ278:        bsr.b    LZ2C8
  94.         bset    d2,d0
  95.         lea    1(a1,d0.w),a3
  96. LZ280:        move.b    -(a3),-(a1)
  97.         dbra    d4,LZ280
  98.         move.b    -(a3),-(a1)
  99.         move.b    -(a3),d0
  100. LZ28A:        move.b    d0,-(a1)
  101.         dbra    d5,LZ258
  102.  
  103.         moveq    #1,d1
  104.         bsr.s    LZ2C8
  105.         bne.w    LZ20A
  106.         rts                ;exit decrunch... bye bye
  107.         
  108. ;----------------------------------------------------------------------------
  109. LZ29C:        moveq    #0,d1
  110.         moveq    #1,d0
  111.         
  112. lz_loop:    sub.w    d0,d7
  113.         beq.s    lz_reloop
  114.         lsr.l    d0,d6
  115.         addx.w    d1,d1
  116.         cmp.w    (a4)+,d1
  117.         bhs.s    lz_loop
  118.         add.w    $3E(a4),d1
  119.         add.w    d1,d1
  120.         move.w    0(a0,d1.w),d0
  121.         rts
  122.  
  123. LZ_reloop    moveq    #17-1,d7
  124.         lsr.l    d0,d6
  125.  
  126.         swap    d6
  127.         move.w    -(a2),d6
  128.         swap    d6
  129.  
  130.         addx.w    d1,d1
  131.         cmp.w    (a4)+,d1
  132.         bhs.s    lz_loop
  133.         add.w    $3E(a4),d1
  134.         add.w    d1,d1
  135.         move.w    0(a0,d1.w),d0
  136.         rts
  137. ;----------------------------------------------------------------------------
  138.  
  139. LZ2C8:        move.w    d6,d0
  140.         lsr.l    d1,d6
  141.         sub.w    d1,d7
  142.         bgt.s    LZ2D8
  143.         add.w    d3,d7
  144.         ror.l    d7,d6
  145.         move.w    -(a2),d6
  146.         rol.l    d7,d6
  147. LZ2D8:        add.w    d1,d1            ;x2
  148.         and.w    .AndData-2(pc,d1.w),d0
  149.         rts
  150. *----------
  151. .AndData:    dc.w    1,3,7,15,$1F,$3F,$7F,$FF,$1FF,$3FF
  152.         dc.w    $7FF,$FFF,$1FFF,$3FFF,$7FFF,$FFFF,$4C53,$4421
  153.  
  154. LZ300:        movem.l    d1-d5/a3,-(sp)
  155.         moveq    #4,d1
  156.         bsr.s    LZ2C8
  157.         move.w    d0,d5
  158.         subq.w    #1,d5
  159.         moveq    #0,d4
  160.         move.l    d4,a3
  161. LZ310:        addq.w    #1,d4
  162.         move.w    d4,d1
  163.         cmp.w    d2,d1
  164.         ble.s    LZ31A
  165.         move.w    d2,d1
  166. LZ31A:        bsr.s    LZ2C8
  167.         move.w    d0,(a0)+
  168.         add.w    d0,a3
  169.         dbra    d5,LZ310
  170.         move.w    a3,d5
  171.         subq.w    #1,d5
  172. LZ328:        move.w    d2,d1
  173.         bsr.s    LZ2C8
  174.         move.w    d0,(a4)+
  175.         dbra    d5,LZ328
  176.         movem.l    (sp)+,d1-d5/a3
  177.         rts
  178.  
  179. lzfast:        moveq    #0,d2
  180.         move.w    d2,d1
  181.         move.w    d2,(a4)+
  182.         moveq    #15-1,d4
  183. loop:        move.w    -2(a4),d0
  184.         add.w    d0,d0            ;x2
  185.         sub.w    d0,64(a4)
  186.         add.w    (a3),d1
  187.         move.w    d1,66(a4)
  188.         add.w    (a3)+,d2
  189.         move.w    d2,(a4)+
  190.         add.w    d2,d2
  191.         dbra    d4,loop
  192.         rts
  193.  
  194. ;-------------- Actual LZHuffman packed datafile
  195.  
  196. source:        incbin    'work:1.pak'
  197. dest:        ds.b    400*1024        ;length of file unpacked (buffer)
  198.